#include "qwdlgmanual.h"

QWDlgManual::QWDlgManual(QWidget *parent)
    : QDialog(parent)
{
    initUI();
    iniSignalSlots();
    setWindowTitle("Form created manually!!!");
}

QWDlgManual::~QWDlgManual()
{

}
void QWDlgManual::on_chkBoxUnder(bool checked)
{
    QFont font=textEdit->font();
    font.setUnderline(checked);
    textEdit->setFont(font);
}

void QWDlgManual::on_chkBoxItalic(bool checked)
{
    QFont font=textEdit->font();
    font.setItalic(checked);
    textEdit->setFont(font);
}

void QWDlgManual::on_chkBoxBold(bool checked)
{
    QFont font=textEdit->font();
    font.setBold(checked);
    textEdit->setFont(font);
}

void QWDlgManual::initUI(){
    chkBoxBold = new QCheckBox(tr("Bold"));
    chkBoxItalic = new QCheckBox(tr("Italic"));
    chkBoxUnder = new QCheckBox(tr("Underline"));
    QHBoxLayout *HLay1 = new QHBoxLayout;
    HLay1->addWidget(chkBoxBold);
    HLay1->addWidget(chkBoxItalic);
    HLay1->addWidget(chkBoxUnder);

    rbtnBlack = new QRadioButton(tr("Black"));
    rbtnBlue = new QRadioButton(tr("Blue"));
    rbtnRed = new QRadioButton(tr("Red"));
    QHBoxLayout *HLay2 = new QHBoxLayout;
    HLay2->addWidget(rbtnBlack);
    HLay2->addWidget(rbtnBlue);
    HLay2->addWidget(rbtnRed);

    btnCancel = new QPushButton(tr("取消"));
    btnOK = new QPushButton(tr("确定"));
    btnclose = new QPushButton(tr("关闭"));
    QHBoxLayout *HLay3 = new QHBoxLayout;
    HLay3->addWidget(btnCancel);
    HLay3->addWidget(btnOK);
    HLay3->addWidget(btnclose);

    textEdit = new QPlainTextEdit;
    textEdit->setPlainText("Hello World \n\nIt is my demo");

    QFont font = textEdit->font();
    font.setPointSize(20);
    textEdit->setFont(font);

    QVBoxLayout *HLay4 = new QVBoxLayout;
    HLay4->addLayout(HLay1);
    HLay4->addLayout(HLay2);
    HLay4->addWidget(textEdit);
    HLay4->addLayout(HLay3);
    setLayout(HLay4);
}

void QWDlgManual::setTextFontColor(){
    QPalette plet=textEdit->palette();
    if(rbtnBlue->isChecked())
        plet.setColor(QPalette::Text,Qt::blue);
    else if(rbtnRed->isChecked())
        plet.setColor(QPalette::Text,Qt::red);
    else if(rbtnBlack->isChecked())
        plet.setColor(QPalette::Text,Qt::black);
    else
        plet.setColor(QPalette::Text,Qt::black);
    textEdit->setPalette(plet);
}

void QWDlgManual::iniSignalSlots(){
    connect(rbtnBlack,SIGNAL(clicked()),this,SLOT(setTextFontColor()));
    connect(rbtnBlue,SIGNAL(clicked()),this,SLOT(setTextFontColor()));
    connect(rbtnRed,SIGNAL(clicked()),this,SLOT(setTextFontColor()));

    connect(chkBoxUnder,SIGNAL(clicked(bool)),this,SLOT(on_chkBoxUnder(bool)));
    connect(chkBoxItalic,SIGNAL(clicked(bool)),this,SLOT(on_chkBoxItalic(bool)));
    connect(chkBoxBold,SIGNAL(clicked(bool)),this,SLOT(on_chkBoxBold(bool)));

    connect(btnCancel,SIGNAL(clicked()),this,SLOT(accept()));
    connect(btnOK,SIGNAL(clicked()),this,SLOT(reject()));
    connect(btnclose,SIGNAL(clicked()),this,SLOT(close()));
}

